

package com.jfinal.aceadmin.model;

import com.jfinal.ext.plugin.tablebind.TableBind;

import com.jfinal.plugin.activerecord.Db;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <a href="Admin.java.html"><b><i>View Source</i></b></a>
 *
 * @author Jason
 *
 */
@TableBind(tableName = "Admin", pkName = "userId")
public class Admin extends BaseModel<Admin> {
	private static final long serialVersionUID = 1L;
	public static Admin dao = new Admin();

	public long getUserId() {
		return this.get("userId");
	}

	public void setUserId(long userId) {
		this.set("userId", userId);
	}

	public String getName() {
		return this.get("name");
	}

	public void setName(String name) {
		this.set("name", name);
	}

	public int getAge() {
		return this.get("age");
	}

	public void setAge(int age) {
		this.set("age", age);
	}

	public Date getCreateDate() {
		return this.get("createDate");
	}

	public void setCreateDate(Date createDate) {
		this.set("createDate", createDate);
	}

	public String getDescription() {
		return this.get("description");
	}

	public void setDescription(String description) {
		this.set("description", description);
	}

	public List<Admin> findByAge(int age) {
		List<Admin> result = new ArrayList<Admin>();
		StringBuilder sBuilder = new StringBuilder("SELECT * FROM Admin WHERE ");
		sBuilder.append("age = ?");

		result = Admin.dao.find(sBuilder.toString(), age);

		return result;
	}

	public int countByAge(int age) {
		int result = 0;
		StringBuilder sBuilder = new StringBuilder(
				"SELECT COUNT(*) FROM Admin WHERE ");
		sBuilder.append("age = ?");
		result = Db.queryLong(sBuilder.toString(), age).intValue();

		return result;
	}

	public Admin findByName(String name) {
		StringBuilder sBuilder = new StringBuilder("SELECT * FROM Admin WHERE ");
		sBuilder.append("name = ?");

		sBuilder.append(" ORDER BY ");
		sBuilder.append("name DESC");
		sBuilder.append(" , ");
		sBuilder.append("createDate ASC");

		Admin result = Admin.dao.findFirst(sBuilder.toString(), name);

		return result;
	}

	public Admin findByNameAndAge(String name, int age) {
		StringBuilder sBuilder = new StringBuilder("SELECT * FROM Admin WHERE ");
		sBuilder.append("name = ?");
		sBuilder.append(" AND ");
		sBuilder.append("age = ?");

		Admin result = Admin.dao.findFirst(sBuilder.toString(), name, age);

		return result;
	}
}